package com.huayue.controller;

import java.util.Calendar;
import java.util.GregorianCalendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.huayue.annotation.LogAnno;
import com.huayue.entity.Logs;
import com.huayue.service.LogsService;
import com.huayue.util.DateHelper;
import com.huayue.util.PageHelper;

/**
 * 日志
 * 
 */
@Controller
@RequestMapping("/logs")
public class LogsController {
    @Autowired
    LogsService svc;

    BaseController bc = new BaseController();

    @LogAnno(operateType = "添加-系统日志")
    @RequestMapping("/add")
    public ModelAndView add(Logs logs) {
        FastJsonJsonView view = new FastJsonJsonView();
        return bc.add(svc, logs);
    }

    @LogAnno(operateType = "修改-系统日志")
    @RequestMapping("/update")
    public ModelAndView update(Logs logs) {
        return bc.update(svc, logs);
    }

    @LogAnno(operateType = "删除-系统日志")
    @RequestMapping("/delete")
    public ModelAndView delete(Logs logs) {
        return bc.delete(svc, logs);
    }

    @RequestMapping("/findOne")
    public ModelAndView findOne(Logs logs) {
        return bc.findOne(svc, logs);
    }

    @RequestMapping("/findPage")
    public ModelAndView findPage(String operateor, PageHelper page, String dateRange) {
        String begin = null;
        String end = null;
        if (dateRange != null && !"".equals(dateRange)) {
            begin = dateRange.split(" - ")[0];
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(DateHelper.StringToDateShort(dateRange.split(" - ")[1]));
            calendar.add(Calendar.DATE, 1);
            end = DateHelper.DateToStringShort(calendar.getTime());
        }
        return bc.findPage(svc, page, null, begin, end, operateor);
    }

}
